package io.renren.common.utils;

import io.renren.modules.medical.entity.DoctorInfoEntity;
import io.renren.modules.medical.entity.IllSubEntity;
import io.renren.modules.medical.entity.QueryPageBaseEntity;
import io.renren.modules.medical.service.DoctorInfoService;
import io.renren.modules.medical.service.IllSubService;
import io.renren.modules.medical.service.PatientInfoService;
import io.renren.modules.medical.vo.medicalVo.QueryPageBaseVo;
import org.springframework.beans.BeanUtils;

/**
 * @author Luo Sheng
 * @school YiBin university
 * @create 2023-04-04 16:25
 */
public class QueryPageUtils {

    /**
     * queryPage方法中抽离出来的方法
     * @param baseVo
     * @param baseEntity
     * @param patientInfoService
     * @param illSubService
     */
    public static QueryPageBaseVo listToVos(QueryPageBaseVo baseVo, QueryPageBaseEntity baseEntity,
                                            PatientInfoService patientInfoService, IllSubService illSubService, DoctorInfoService doctorInfoService){
        BeanUtils.copyProperties(baseEntity, baseVo);
        String patientName = patientInfoService.getNameById(baseEntity.getPatientId());
        baseVo.setPatientName(patientName != null && !patientName.equals("") ? patientName : "");
        IllSubEntity illSubEntity = null;
        if (baseEntity.getSubId() != null) {
            illSubEntity = illSubService.getById(baseEntity.getSubId());
            baseVo.setSubTitle(illSubEntity != null ? illSubEntity.getTitle() : "");
        }
        if (baseEntity.getDoctorId() != null){
            DoctorInfoEntity doctorInfoEntity = doctorInfoService.getById(baseEntity.getDoctorId());
            baseVo.setDoctorName(doctorInfoEntity.getName() != null ? doctorInfoEntity.getName() : "");
        }

        return baseVo;
    }

}
